package models;

import java.util.Collections;

import javax.cache.Cache;
import javax.cache.CacheException;
import javax.cache.CacheManager;

import com.googlecode.objectify.Key;
import com.googlecode.objectify.Objectify;
import com.googlecode.objectify.ObjectifyOpts;
import com.googlecode.objectify.ObjectifyService;

import entities.AdsenseAdv;


public class AdsenseAdvModel {
	private Objectify ofy;
	
	private Cache cache = null;
	
	private static AdsenseAdvModel instance = null;
	
	public static AdsenseAdvModel getInstance() {
		if (instance == null) {
			instance = new AdsenseAdvModel();
		}
		
		return instance;
	}
	
	private AdsenseAdvModel() {		
		try {
			ObjectifyService.register(AdsenseAdv.class);
		} catch (Exception e) {
			// TODO: handle exception
		}
		
		try {
            cache = CacheManager.getInstance().getCacheFactory().createCache(Collections.emptyMap());
        } catch (CacheException e) {
           //e.printStackTrace();
        }
		
        ObjectifyOpts opts = new ObjectifyOpts().setSessionCache(true);
		ofy = ObjectifyService.begin(opts);
	}
	
	public AdsenseAdv get(String id) {
		AdsenseAdv adv = new AdsenseAdv();
		try {
			adv = ofy.get(new Key<AdsenseAdv>(AdsenseAdv.class, id));
		} catch (Exception e) {
			adv = new AdsenseAdv();
			adv.setId(id);
		}
		
		
		return adv;
	}
	
	public AdsenseAdv get200x200(String id) {
		
		AdsenseAdv adv = get("200x200");
		
		return adv;
	}
	
	public AdsenseAdv get234x60(String id) {
		
		AdsenseAdv adv = get("234x60");
		
		return adv;
	}
	
	public AdsenseAdv get300x250(String id) {
		
		AdsenseAdv adv = get("300x250");
		
		return adv;
	}
	
	public AdsenseAdv get336x280(String id) {
		
		AdsenseAdv adv = get("336x280");
		
		return adv;
	}
	
	public AdsenseAdv get468x15(String id) {
		
		AdsenseAdv adv = get("468x15");
		
		return adv;
	}
	
	public AdsenseAdv get468x60(String id) {
		
		AdsenseAdv adv = get("468x60");
		
		return adv;
	}
	
	public AdsenseAdv get728x15(String id) {
		
		AdsenseAdv adv = get("728x15");
		
		return adv;
	}
	
	public AdsenseAdv get728x90(String id) {
		
		AdsenseAdv adv = get("728x90");
		
		return adv;
	}
}
